<script>
	import base64 from '@/utils/base64.js';
	import { mapActions, mapMutations } from 'vuex';
	export default {
		onLaunch: function() {
			uni.removeStorageSync('noticePopDis');
			console.log('App Launch');
			// #ifdef MP
			const accountInfo = uni.getAccountInfoSync();
			const miniCode = base64.encode(accountInfo.miniProgram.appId);
			uni.setStorageSync('miniCode', miniCode);
			const menuButtonInfo = uni.getMenuButtonBoundingClientRect();
			this.setMenuButtonInfo(menuButtonInfo);
			// 检查是否是小程序最新版
			this.getUpdateManager()
			// #endif
		},
		onExit() {
			uni.removeStorageSync('noticePopDis');
		},
		onShow: function() {
			const memberId = uni.getStorageSync('memberId');
			if (memberId) {
				this.getUserInfo();
			}
 			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			...mapMutations('home', ['setMenuButtonInfo']),
			...mapActions('user', ['getUserInfo']),
			//检查小程序是否是最新版
			getUpdateManager () {
				const updateManager = uni.getUpdateManager();
				updateManager.onUpdateReady(function (res) {
					uni.showModal({
						title: '更新提示',
						content: '新版本已经准备好,是否重启应用?',
						success(res) {
							if (res.confirm) {
								//新的版本已经下载好,调用applyUpdate 应用新版本并重启
								updateManager.applyUpdate();
							}
						}
					})
				})
			}
		}
	}
</script>

<style>
	/*每个页面公共css */
	@import url('style/index.css');
</style>
